﻿using Abp.Domain.Entities;
using IntelligentAgriculture.Contracts.Dto.Input.RidgepInput;
using IntelligentAgriculture.Contracts.Interface.IManagements;
using IntelligentAgriculture.Contracts.Interface.Iridgepletype;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Services.Management;
using IntelligentAgriculture.WebAPI.Application.Command.ManageCommand;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCommand;
using MediatR;
using Microsoft.EntityFrameworkCore.Internal;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.RidgepCommandHandler
{
    public class RidgepUpdateCommandHandler : IRequestHandler<RidgepUpdateCommand, Results<int>>
    {
        private readonly IridegpoleService _iregisteredServices;

        public RidgepUpdateCommandHandler(IridegpoleService iregisteredServices)
        {
            _iregisteredServices = iregisteredServices;
        }
        /// <summary>
        /// 修改功能，用于执行对数据的修改操作。
        /// </summary>
        /// <param name="request">表示修改请求的对象</param>
        /// <param name="cancellationToken">用于取消操作的取消令牌</param>
        /// <returns>返回受影响行数</returns>
        public async Task<Results<int>> Handle(RidgepUpdateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var list = new Ridgepole()
                {
                    SheepId = request.SheepId,
                    State = request.State,
                    CreateName = request.CreateName,
                    CreateTime = request.CreateTime,
                    ProductionPersonnel = request.ProductionPersonnel,
                    Remark = request.Remark,
                    ResponsiblePerson = request.ResponsiblePerson,
                    RidgepoleId = request.RidgepoleId,
                    RidgepoleName = request.RidgepoleName,
                    RidgepoleTypeId = request.RidgepoleTypeId,
                    UpdateName = request.UpdateName,
                    UpdateTime = DateTime.Now

                };
                var lists = await _iregisteredServices.Update(list);
                return Results<int>.DataResult(lists);

               
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
